package com.ichina.chat.util;

public class StringReplacer {
	private String str;  
	  
    public StringReplacer(String src, String before, String after) {  
       str = replaceString(src, before, after);  
    }  
  
    public String toString() {  
       return str;  
    }  
  
    public static String replaceString(String str,String before,String after) {  
      StringBuffer sb = new StringBuffer();  
      int oldidx = 0;  
      int idx = str.indexOf(before);  
      while (idx != -1) {  
        sb.append(str.substring(oldidx, idx)).append(after);  
        oldidx = idx + before.length();  
        idx = str.indexOf(before, oldidx);  
      }  
      if (oldidx < str.length())  
        sb.append(str.substring(oldidx));  
      return sb.toString();  
    } 
    public static String replaceString(String str,String[] before,String[] after){
    	for(int i = 0 ; i < before.length; i++){
    		str = StringReplacer.replaceString(str,before[i],after[i]);
    	}
    	return str;
    }
    
}
